package com.common.pojo;

import com.common.base.BaseEnum;

/**
* @version: V1.0
* @author: szw
* @className: Result
* @packageName: Result
* @description: 统一结果返回类
* @data: 2021-1-19 
**/  
public class Result<T> {
    private Integer code;
    private String msg;
    private String message;
    private String token;
    private T data;


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setOk(T data) {
        this.data = data;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public Result OK(T t){
        this.setCode(Integer.valueOf(BaseEnum.SUCESS.getCode()));
        this.setMsg(BaseEnum.SUCESS.getDesc());
        this.setOk(t);
        return this;
    }

    public Result fail(String msg){
        this.setCode(1001);
        this.setMsg(msg);
        this.setMessage(msg);
        return this;
    }
    public Result loginOk(String token, T t){
        this.setCode(Integer.valueOf(BaseEnum.SUCESS.getCode()));
        this.setMsg(BaseEnum.SUCESS.getDesc());
        this.OK(t);
        this.setToken(token);
        return this;
    }


    public Result() {
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
        this.setMessage(msg);
    }

    public Result(BaseEnum baseEnum) {
        this.code = Integer.valueOf(baseEnum.getCode());
        this.msg = baseEnum.getDesc();
        this.setMessage(msg);
    }

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.setMessage(msg);
    }

    @Override
    public String toString() {
        return "BaseResult{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
